package com.deng.mina.common.protocol;

/**
 * @Project
 * @Module
 * @JDK_Vserion 1.8
 * @Author DengLibin
 * @Email dlb@smarthse.cn
 * @Desc 自定义协议 数据包（发送接收都使用该对象）
 * @since 2019/9/18 0018 9:38
 */
public class ProtocolPack {
    private int length; // (包头)整个数据包的长度(包含包头和内容)用于处理粘包
    private byte flag; // （包头）标记

    private String content; // 内容

    public ProtocolPack(byte flag, String content) {
        this.flag = flag;
        this.content = content;
        int len1 = content == null ? 0 : content.getBytes().length; // 内容长度
        this.length = 5 + len1; // length 占4个字节，byte占1个字节 共5个字节
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public byte getFlag() {
        return flag;
    }

    public void setFlag(byte flag) {
        this.flag = flag;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "ProtocolPack{" +
                "length=" + length +
                ", flag=" + flag +
                ", content='" + content + '\'' +
                '}';
    }
}
